package yun.http.rechochoku.response;

import org.json.JSONException;
import org.json.JSONObject;
import yun.common.http.response.JSONResponse;

public class FailureResponse extends JSONResponse {
	private static final String ERROR = "error";
	private static final String CODE = "code";
	private static final String MESSAGE = "message";

	private int mCode;
	private String mMessage;

	FailureResponse() {
		super();
	}

	public int getCode() {
		return mCode;
	}

	public String getMessage() {
		return mMessage;
	}

	@Override
	public JSONResponse parse(JSONObject json) throws JSONException {
		JSONObject error = json.getJSONObject(ERROR);
		mCode = error.getInt(CODE);
		mMessage = error.getString(MESSAGE);
		return this;
	}
	
	@Override
	public String toString() {
		StringBuilder toString = new StringBuilder();
		toString.append("+--<FailureResponse>---").append('\n');
		toString.append("| ").append("code").append("   =").append(mCode).append('\n');
		toString.append("| ").append("message").append('=').append(mMessage).append('\n');
		toString.append("+--------------------").append('\n');
		return toString.toString();
	}
}
